package com.atguigu.spzx.common.exception;

import com.atguigu.spzx.model.vo.common.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(value = Exception.class)
    public Result systemExceptionHandler(Exception exception){
        System.out.println("Exception通用通知");
        exception.printStackTrace();
        return Result.FAIL(exception.getMessage());
    }

    @ExceptionHandler(NullPointerException.class)
    public Result nullPointerException(NullPointerException exception){
        System.out.println("空指针通知");
        exception.printStackTrace();
        return Result.FAIL(exception.getMessage());
    }

    @ExceptionHandler(IllegalArgumentException.class)
    public Result illegalArgumentException(IllegalArgumentException exception){
        System.out.println("非法参数通知");
        exception.printStackTrace();
        return Result.FAIL(exception.getMessage());
    }

    @ExceptionHandler(value = GuiguException.class)
    public Result guiguExceptionHandler(GuiguException exception) {
        System.out.println("业务逻辑错误");
        exception.printStackTrace();
        return Result.FAIL(exception.getMessage());
    }



}
